<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../css/common.css" media="all">
	</head>
	<body>

		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-card">
					<form class="layui-form test_edit" lay-filter='example' onsubmit="return false" action="##" id="form">
						<div class="layui-form-item">
							<label class="layui-form-label" id="labelTxt" style="width: auto;">图片/视频上传：</label>
							<button type="button" class="layui-btn" id="test2">选择文件上传</button>
							<!--<span>共(<span id="total">0</span>)张，成功上传（<span id="successtotal">0</span>）张</span>-->
							<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
								预览图：
								<div class="layui-upload-list" id="demo2"></div>
							</blockquote>
							<!-- <button type="button" class="layui-btn layui-btn-normal" id="choose">选择文件上传</button> -->
							<!-- <button type="button" class="layui-btn" id="up">开始上传</button> -->
						</div>
						<div class="layui-form-item layui-layout-admin">
							<div class="layui-input-block">
								<div class="layui-footer" style="left: 0;">
									<button class="layui-btn" id="queding">确定</button>
								</div>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>

		<script src="../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../js/common.js"></script>
		<script>
			var _data = {
				type: getParam('type')
			}
			
			layui.config({
				base: '../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'form', 'upload'], function() {
				var $ = layui.$,
					admin = layui.admin,
					upload = layui.upload,
					form = layui.form;
				
				var img_arr = [];
				 //多图片上传
				if(_data.type == 3) {
					$("#labelTxt").html('视频上传')
					var index1 = null;
					upload.render({
						elem: '#test2',
						url: server.upimg,
						accept: 'video',
						multiple: true,
						before: function(obj) {
							//预读本地文件示例，不支持ie8
							var index = layer.load(1, {
								shade: [0.1, '#fff'] //0.1透明度的白色背景
							});
							obj.preview(function(index, file, result) {
								$('#demo2').append('<div><video src="' + result + '" alt="' + file.name + '" style="width: 100%;height:100%"></video></div>')
							});
						},
						done: function(res) {
							//上传完毕
							layer.msg('上传成功')
							img_arr.push(res.file);
							closeloading()
							// console.log(res.file);
						}
					});
				} else if(_data.type == 10){
					// 文档或pdf文件上传
					$("#labelTxt").html('文件上传')
					upload.render({
						elem: '#test2',
						url: server.upimg,
						accept: 'file',
						before: function(obj) {
							//预读本地文件示例，不支持ie8
							obj.preview(function(index, file, result) {
								if(file.name.indexOf('.ppt') > -1 || file.name.indexOf('.pptx') > -1){
									$('#demo2').append('<div class="show_img_li"><img src="../../../img/ppt.png" alt="' + file.name + '" class="layui-upload-img"><p>' + file.name + '</p><div>')
								} else if(file.name.indexOf('.pdf') > -1){
									$('#demo2').append('<div class="show_img_li"><img src="../../../img/pdf.png" alt="' + file.name + '" class="layui-upload-img"><p>' + file.name + '</p><div>')
								} else if(file.name.indexOf('.txt') > -1){
									$('#demo2').append('<div class="show_img_li"><img src="../../../img/txt.png" alt="' + file.name + '" class="layui-upload-img"><p>' + file.name + '</p><div>')
								} else if(file.name.indexOf('.doc') > -1 || file.name.indexOf('.docx') > -1){
									$('#demo2').append('<div class="show_img_li"><img src="../../../img/word.png" alt="' + file.name + '" class="layui-upload-img"><p>' + file.name + '</p><div>')
								} else if(file.name.indexOf('.xls') > -1 || file.name.indexOf('.xlsx') > -1){
									$('#demo2').append('<div class="show_img_li"><img src="../../../img/excel.png" alt="' + file.name + '" class="layui-upload-img"><p>' + file.name + '</p><div>')
								} else {
									$('#demo2').append('<img src="' + result + '" alt="' + file.name + '" class="layui-upload-img">')
								}
							});
						},
						done: function(res,index, upload) {
							//上传完毕
							if (res.code == 0) {
								img_arr.push(res.file);
							} else {
								layer.msg('上传失败，请重新上传')
							}
							/* console.log($('#demo2>img')[index.split('-')[1]]);
							console.log(res.file); */
						},
						error: function (index, upload) {
							layer.msg('上传失败，请重新上传')
						},
					}); 
				} else {
					//多图片上传
					$("#labelTxt").html('图片上传')
					upload.render({
						elem: '#test2',
						url: server.upimg, 
						multiple: true,
						before: function(obj) {
							//预读本地文件示例，不支持ie8
							obj.preview(function(index, file, result) {
								$('#demo2').append('<img src="' + result + '" alt="' + file.name + '" class="layui-upload-img">')
							});
						},
						done: function(res,index, upload) {
							//上传完毕
							 if (res.code == 0) {
								img_arr.push(res.file);
							} else {
								layer.msg('上传失败，请重新上传')
							}
							/* console.log($('#demo2>img')[index.split('-')[1]]);
							console.log(res.file); */
						},
						 error: function (index, upload) {
							layer.msg('上传失败，请重新上传')
						},
						allDone: function(obj){ //当文件全部被提交后，才触发
							$('#total').html(Number($('#total').html()) + obj.total)
							$('#successtotal').html(Number($('#successtotal').html()) + obj.successful)
						}
					}); 
				}
				$('#queding').on('click',function(){
					parent.getimg(img_arr.join(','),_data.type);
					var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
					parent.layer.close(index); //再执行关闭
				});
			});
		</script>
	</body>
</html>
